<?php

class ThongkeController extends BaseController {

    public function getIndex() {
        return View::make('thong_kes.index');
    }

    public function getTkhocvien() {
        $query = 'SELECT CONCAT(tai_khoans.ho_cb, " ",tai_khoans.ten_cb)  AS hoten FROM tai_khoans WHERE tai_khoans.id = ' . Auth::user()->id;
        $ten_can_bo = DB::select($query);
        // return $ten_can_bo;
        // Danh sách năm khoá thi
        $khoa_thi = new Khoa_thi();
        $ds_nam = $khoa_thi->ds_nam_khoa_thi();
        $ds_hoi_dong_thi = Hoi_dong_thi::all();
        $ds_khoa_thi = Khoa_thi::all();
        // return $ds_khoa_thi;
        return View::make('thong_kes.tkhocvien')->with(
                        array('ds_nam' => $ds_nam,
                            'ds_hoi_dong_thi' => $ds_hoi_dong_thi,
                            'ds_khoa_thi' => $ds_khoa_thi,
                            'ten_can_bo' => $ten_can_bo));
    }
    public function getTkbangcap() {
        $query = 'SELECT CONCAT(tai_khoans.ho_cb, " ",tai_khoans.ten_cb)  AS hoten FROM tai_khoans WHERE tai_khoans.id = ' . Auth::user()->id;
        $ten_can_bo = DB::select($query);
        //Danh sách năm khoá thi
        $khoa_thi = new Khoa_thi();
        $ds_nam = $khoa_thi->ds_nam_khoa_thi();
        //Danh sách hội đồng thi
        $ds_hoi_dong_thi = Hoi_dong_thi::all();
        //Danh sách khoá thi
        $ds_khoa_thi = Khoa_thi::all();
        //Danh sách chứng chỉ
        $ds_chung_chi = Chung_chi::all();
        // return $ds_khoa_thi;
        return View::make('thong_kes.tkbangcap')
                ->with(array(
                            'ds_nam' => $ds_nam,
                            'ds_hoi_dong_thi' => $ds_hoi_dong_thi,
                            'ds_khoa_thi' => $ds_khoa_thi,
                            'ds_chung_chi' => $ds_chung_chi,
                            'ten_can_bo' => $ten_can_bo));
    }
    public function getTkketqua() {
        $query = 'SELECT CONCAT(tai_khoans.ho_cb, " ",tai_khoans.ten_cb)  AS hoten FROM tai_khoans WHERE tai_khoans.id = ' . Auth::user()->id;
        $ten_can_bo = DB::select($query);
        //Danh sách năm khoá thi
        $khoa_thi = new Khoa_thi();
        $ds_nam = $khoa_thi->ds_nam_khoa_thi();
        //Danh sách hội đồng thi
        $ds_hoi_dong_thi = Hoi_dong_thi::all();
        //Danh sách khoá thi
        $ds_khoa_thi = Khoa_thi::all();
        //Danh sách chứng chỉ
        $ds_chung_chi = Chung_chi::all();
        // return $ds_khoa_thi;
        return View::make('thong_kes.tkketqua')->with(
                        array(
                            'ds_nam' => $ds_nam,
                            'ds_hoi_dong_thi' => $ds_hoi_dong_thi,
                            'ds_khoa_thi' => $ds_khoa_thi,
                            'ds_chung_chi' => $ds_chung_chi,
                            'ten_can_bo' => $ten_can_bo));
    }
    public function postKetqua() {
        $array_khoa_thi = Input::get('khoa_thi');
        $array_hoi_dong_thi = Input::get('hoi_dong_thi');
        $array_chung_chi = Input::get('chung_chi');
        $ngay_thi = Input::get('ngay_thi');
        $tu_ngay = substr($ngay_thi, 0, 10);
        $den_ngay = substr($ngay_thi, 13, 23);

        $array_khoa_thi_temp = str_replace("[", "(", json_encode($array_khoa_thi));
        $array_khoa_thi_temp = str_replace("]", ")", $array_khoa_thi_temp);
        $array_khoa_thi_temp = str_replace("\"", "", $array_khoa_thi_temp);

        $array_chung_chi_temp = str_replace("[", "(", json_encode($array_chung_chi));
        $array_chung_chi_temp = str_replace("]", ")", $array_chung_chi_temp);
        $array_chung_chi_temp = str_replace("\"", "", $array_chung_chi_temp);

        $array_hoi_dong_thi_temp = str_replace("[", "(", json_encode($array_hoi_dong_thi));
        $array_hoi_dong_thi_temp = str_replace("]", ")", $array_hoi_dong_thi_temp);
        $array_hoi_dong_thi_temp = str_replace("\"", "", $array_hoi_dong_thi_temp);

        $html = '<table border="1" style="width: 100%;border-collapse: collapse;" id="table_data" summary="Code page support in different versions of MS Windows."   ><thead>';
        $html .= '<tr >';
        $html .= '<th style="text-align: center">STT</th>';
        $html .= '<th style="text-align: center">Chứng Chỉ</th>';
        $html .= '<th style="text-align: center">Khóa Thi</th>';
        $html .= '<th style="text-align: center">Số học viên đạt</th>';
        $html .= '<th style="text-align: center">Số học viên không đạt</th>';
        $html .= '<th style="text-align: center">Ghi Chú</th>';
        $html .= '</tr>';
        $html .= '</thead>';
        $html .= '<tbody>';
        $i = 0;
        foreach ($array_hoi_dong_thi as $array_hoi_dong_thi) {
         
            $ten_hoi_dong_thi = DB::table('hoi_dong_this')->where('id',$array_hoi_dong_thi)->pluck('ten_hoi_dong_thi');
            $html .= '<tr>';
            $html .= '<td style="text-align: center" colspan="6">' . $ten_hoi_dong_thi . '</td>';
            $html .= '</tr>';

            foreach ($array_chung_chi as $array_chung_chi ) {
                $ten_chung_chi = DB::table('chung_chis')->where('id',$array_chung_chi)->pluck('ten_chung_chi');
                

                $query_khoa_thi = 'select khoa_this.id, khoa_this.ma_khoa_thi FROM hoc_viens '
                . ' INNER JOIN khoa_this ON hoc_viens.KhoaThi_Id = khoa_this.id'
                . ' INNER JOIN hoi_dong_this ON khoa_this.HoiDongThi_Id = hoi_dong_this.id'
                . ' INNER JOIN chung_chis ON hoc_viens.ChungChi_Id = chung_chis.id'
                . ' where hoi_dong_this.id = \'' . $array_hoi_dong_thi. '\''
                . ' and chung_chis.id = \'' . $array_chung_chi . '\''
                . ' and khoa_this.id in ' . $array_khoa_thi_temp
                . ' and DATEDIFF(str_to_date(\'' . $tu_ngay . '\',"%d/%m/%Y"),str_to_date(khoa_this.ngay_thi,"%d/%m/%Y")) <= 0  '
                . ' and DATEDIFF(str_to_date(\'' . $den_ngay . '\',"%d/%m/%Y"),str_to_date(khoa_this.ngay_thi,"%d/%m/%Y")) >= 0 '
                . ' GROUP BY khoa_this.id';

                 
                $results_khoa_thi = DB::select($query_khoa_thi);

                foreach ($results_khoa_thi as $results_khoa_thi) {
                    $i++;
                        $results_pass = DB::table('hoc_viens')
                                            ->where('KhoaThi_Id',$results_khoa_thi->id)
                                            ->where('ket_qua','=','1')
                                            ->count('ket_qua');

                        $results_not_pass = DB::table('hoc_viens')
                                            ->where('KhoaThi_Id',$results_khoa_thi->id)
                                            ->where('xep_loai','=','Kh. đạt')
                                            ->count('ket_qua');
                    $html .= '<tr>';
                    $html .= '<td style="text-align: center">' . $i . '</td>';
                    $html .= '<td style="text-align: center">' . $ten_chung_chi . '</td>';
                    $html .= '<td style="text-align: center">' . $results_khoa_thi->ma_khoa_thi . '</td>';
                    $html .= '<td style="text-align: center">' . $results_pass. '</td>';
                    $html .= '<td style="text-align: center">' . $results_not_pass . '</td>';
                    $html .= '<td style="text-align: center"></td>';
                    $html .= '</tr>';
                }
            }

        }
 

        


        $query_count_dat = 'select count(*) as dat FROM hoc_viens '
                . ' INNER JOIN khoa_this ON hoc_viens.KhoaThi_Id = khoa_this.id'
                . ' INNER JOIN hoi_dong_this ON khoa_this.HoiDongThi_Id = hoi_dong_this.id'
                . ' INNER JOIN chung_chis ON hoc_viens.ChungChi_Id = chung_chis.id'
                . ' where hoi_dong_this.id in ' . $array_hoi_dong_thi_temp
                . ' and khoa_this.id in ' . $array_khoa_thi_temp
                . ' and chung_chis.id in ' . $array_chung_chi_temp
                . ' and DATEDIFF(str_to_date(\'' . $tu_ngay . '\',"%d/%m/%Y"),str_to_date(khoa_this.ngay_thi,"%d/%m/%Y")) <= 0  '
                . ' and DATEDIFF(str_to_date(\'' . $den_ngay . '\',"%d/%m/%Y"),str_to_date(khoa_this.ngay_thi,"%d/%m/%Y")) >= 0 '
                . ' and hoc_viens.ket_qua = 1';
                // echo $query_count_dat;
        $results_count_dat = DB::select($query_count_dat);
        foreach ($results_count_dat as $results_count_dat) {
            $results_count_dat = $results_count_dat->dat;
        }
        $query_count_khong_dat = 'select count(*) as khongdat FROM hoc_viens '
                . ' INNER JOIN khoa_this ON hoc_viens.KhoaThi_Id = khoa_this.id'
                . ' INNER JOIN hoi_dong_this ON khoa_this.HoiDongThi_Id = hoi_dong_this.id'
                . ' INNER JOIN chung_chis ON hoc_viens.ChungChi_Id = chung_chis.id'
                . ' where hoi_dong_this.id in ' . $array_hoi_dong_thi_temp
                . ' and khoa_this.id in ' . $array_khoa_thi_temp
                . ' and chung_chis.id in ' . $array_chung_chi_temp
                . ' and DATEDIFF(str_to_date(\'' . $tu_ngay . '\',"%d/%m/%Y"),str_to_date(khoa_this.ngay_thi,"%d/%m/%Y")) <= 0  '
                . ' and DATEDIFF(str_to_date(\'' . $den_ngay . '\',"%d/%m/%Y"),str_to_date(khoa_this.ngay_thi,"%d/%m/%Y")) >= 0 '
                . ' and hoc_viens.ket_qua = 0';
        $results_count_khong_dat = DB::select($query_count_khong_dat);
        foreach ($results_count_khong_dat as $results_count_khong_dat) {
            $results_count_khong_dat = $results_count_khong_dat->khongdat;
        }
        $html .= '<tr>';
        $html .= '<td colspan="3" style="text-align: center">Tổng số học viên</td>';
        $html .= '<td colspan="1" style="text-align: center">' . $results_count_dat . '</td>';
        $html .= '<td colspan="1" style="text-align: center">' . $results_count_khong_dat . '</td>';
        $html .= '<td colspan="1" style="text-align: center"></td>';
        $html .= '</tr>';
        $html .= '</tbody>';
        $html .= '</table>';
        echo $html;
    }
    
    public function postTonghop() {
        $array_khoa_thi = Input::get('khoa_thi');
        $array_hoi_dong_thi = Input::get('hoi_dong_thi');
        $array_ket_qua = Input::get('ket_qua');

        $ngay_thi = Input::get('ngay_thi');
        $tu_ngay = substr($ngay_thi, 0, 10);
        $den_ngay = substr($ngay_thi, 13, 23);

        $array_hoi_dong_thi = str_replace("[", "(", json_encode($array_hoi_dong_thi));
        $array_hoi_dong_thi = str_replace("]", ")", $array_hoi_dong_thi);
        $array_hoi_dong_thi = str_replace("\"", "", $array_hoi_dong_thi);

        $array_khoa_thi = str_replace("[", "(", json_encode($array_khoa_thi));
        $array_khoa_thi = str_replace("]", ")", $array_khoa_thi);
        $array_khoa_thi = str_replace("\"", "", $array_khoa_thi);

        $array_ket_qua = str_replace("[", "(", json_encode($array_ket_qua));
        $array_ket_qua = str_replace("]", ")", $array_ket_qua);
        $array_ket_qua = str_replace("\"", "", $array_ket_qua);

 
        $query = 'select * FROM hoc_viens '
                . ' INNER JOIN khoa_this ON hoc_viens.KhoaThi_Id = khoa_this.id'
                . ' INNER JOIN hoi_dong_this ON khoa_this.HoiDongThi_Id = hoi_dong_this.id'
                . ' INNER JOIN chung_chis ON hoc_viens.ChungChi_Id = chung_chis.id'
                . ' where hoi_dong_this.id in ' . $array_hoi_dong_thi
                . ' and khoa_this.id in ' . $array_khoa_thi
                . ' and hoc_viens.ket_qua in ' . $array_ket_qua
                . ' and DATEDIFF(str_to_date(\'' . $tu_ngay . '\',"%d/%m/%Y"),str_to_date(khoa_this.ngay_thi,"%d/%m/%Y")) <= 0  '
                . ' and DATEDIFF(str_to_date(\'' . $den_ngay . '\',"%d/%m/%Y"),str_to_date(khoa_this.ngay_thi,"%d/%m/%Y")) >= 0 '
                . ' ORDER BY hoi_dong_this.id asc, chung_chis.id asc, khoa_this.id asc, hoc_viens.sbd asc';
        
        $results = DB::select($query);
        $html = '<div id="tong_so_hang"></div><br/>';
        $html .= '<table border="1" style="width: 100%;border-collapse: collapse;" id="table_data" summary="Code page support in different versions of MS Windows."   ><thead>';
        $html .= '<tr >';
        $html .= '<th style="text-align: center">SBD</th>';
        $html .= '<th style="text-align: center">Mã Học Viên</th>';
        $html .= '<th style="text-align: center">Họ Tên</th>';
        $html .= '<th style="text-align: center">Ngày Sinh</th>';
        $html .= '<th style="text-align: center">Giới Tính</th>';
        $html .= '<th style="text-align: center">Khoá Thi</th>';
        $html .= '<th style="text-align: center">Tên Chứng Chỉ</th>';
        $html .= '<th style="text-align: center">Số Hiệu Bằng</th>';
        $html .= '<th style="text-align: center">Số Sổ Cấp Chứng Chỉ</th>';
        $html .= '<th style="text-align: center">Số Quyết Định Tốt Nghiệp</th>';
        $html .= '</tr>';
        $html .= '</thead>';
        $html .= '<tbody>';
        //Biến tạm							
        $tong_so_hang = 0;
        $dat = 0;
        $khong_dat = 0;
        $temp_hoi_dong_thi = '';
        foreach ($results as $results) {
            $tong_so_hang++;
            $temp = $results->ma_hoi_dong_thi;
            if ($temp != $temp_hoi_dong_thi) {

                $query_count = 'select * FROM hoc_viens '
                        . ' INNER JOIN khoa_this ON hoc_viens.KhoaThi_Id = khoa_this.id'
                        . ' INNER JOIN hoi_dong_this ON khoa_this.HoiDongThi_Id = hoi_dong_this.id'
                        . ' INNER JOIN chung_chis ON hoc_viens.ChungChi_Id = chung_chis.id'
                        . ' where  khoa_this.id in ' . $array_khoa_thi
                        . ' and hoc_viens.ket_qua in ' . $array_ket_qua
                        . ' and hoi_dong_this.ma_hoi_dong_thi = ' . '\''.$temp . '\''
                        . ' and DATEDIFF(str_to_date(\'' . $tu_ngay . '\',"%d/%m/%Y"),str_to_date(khoa_this.ngay_thi,"%d/%m/%Y")) <= 0  '
                        . ' and DATEDIFF(str_to_date(\'' . $den_ngay . '\',"%d/%m/%Y"),str_to_date(khoa_this.ngay_thi,"%d/%m/%Y")) >= 0 '
                        . ' ORDER BY hoi_dong_this.id asc, chung_chis.id asc, khoa_this.id asc, hoc_viens.sbd asc';

                $dat = 0;
                $khdat = 0;
                $results_count = DB::select($query_count);
                foreach ($results_count as $results_count ) {
                    if(trim($results_count->xep_loai) == 'Kh. đạt'){
                        $khdat++;
                    }
                    elseif(trim($results_count->xep_loai) == ''){
                       $khdat++;
                    }else{
                        $dat++;
                    }
                }
          

                $html .= '<tr style="background: #E7E7E7;color: #000;">';
                // $html .= '<td colspan="11"><h5><p>' . $results->ten_hoi_dong_thi . '</p></h5></td>';
                $html .= '<td colspan="11"><p><h5>' . $results->ten_hoi_dong_thi . '(Học viên đạt:'. $dat.' - Học viên không đạt:'. $khdat.')</h5></p></td>';
                $html .= '</tr>';
                $temp_hoi_dong_thi = $temp; 
            }
            $html .= '<tr>';
            $html .= '<td>' . $results->sbd . '</td>';
            $html .= '<td>' . $results->ma_hv . '</td>';
            $html .= '<td>' . $results->ho_hv . ' ' . $results->ten_hv . '</td>';
            $html .= '<td>' . $results->ngay_sinh_hv . '</td>';
            $html .= '<td>' . $results->gioi_tinh_hv . '</td>';
            $html .= '<td>' . $results->ma_khoa_thi . '</td>';
            $html .= '<td>' . $results->ten_chung_chi . '</td>';
            $html .= '<td>' . $results->so_hieu_bang . '</td>';
            $html .= '<td>' . $results->so_so_cap_chung_chi . '</td>';
            $html .= '<td>' . $results->so_quyet_dinh_tot_nghiep . '</td>';
            $html .= '</tr>';
             
        }
     
        $html .= '</tbody>';
        $html .= '</table>';
        if ($tong_so_hang == '0') {
            $html = '<table border="1" style="width: 100%;border-collapse: collapse;" id="table_data" summary="Code page support in different versions of MS Windows."   ><thead>';
            $html .= '<tr >';
            $html .= '<th style="text-align: center">SBD</th>';
            $html .= '<th style="text-align: center">Mã Học Viên</th>';
            $html .= '<th style="text-align: center">Họ Tên</th>';
            $html .= '<th style="text-align: center">Ngày Sinh</th>';
            $html .= '<th style="text-align: center">Giới Tính</th>';
            $html .= '<th style="text-align: center">Khoá Thi</th>';
            $html .= '<th style="text-align: center">Tên Chứng Chỉ</th>';
            $html .= '<th style="text-align: center">Số Hiệu Bằng</th>';
            $html .= '<th style="text-align: center">Số Sổ Cấp Chứng Chỉ</th>';
            $html .= '<th style="text-align: center">Số Quyết Định Tốt Nghiệp</th>';
            $html .= '</tr>';
            $html .= '</thead>';
            $html .= '<tbody>';
            $html .= "<tr><td colspan='10'><center>Không có dữ liệu thống kê!!!</center></td></tr>";
            $html .= '</tbody>';
            $html .= '</table>';
            echo $html;
        } else {
            echo $html;
        }
    }

    public function postVanbang() {
        $array_khoa_thi = Input::get('khoa_thi');
        $array_hoi_dong_thi = Input::get('hoi_dong_thi');
        $array_chung_chi = Input::get('chung_chi');
        $ngay_thi = Input::get('ngay_thi');
        $tu_ngay = substr($ngay_thi, 0, 10);
        $den_ngay = substr($ngay_thi, 13, 23);

        $array_khoa_thi_temp = str_replace("[", "(", json_encode($array_khoa_thi));
        $array_khoa_thi_temp = str_replace("]", ")", $array_khoa_thi_temp);
        $array_khoa_thi_temp = str_replace("\"", "", $array_khoa_thi_temp);

        $array_chung_chi_temp = str_replace("[", "(", json_encode($array_chung_chi));
        $array_chung_chi_temp = str_replace("]", ")", $array_chung_chi_temp);
        $array_chung_chi_temp = str_replace("\"", "", $array_chung_chi_temp);

        $array_hoi_dong_thi_temp = str_replace("[", "(", json_encode($array_hoi_dong_thi));
        $array_hoi_dong_thi_temp = str_replace("]", ")", $array_hoi_dong_thi_temp);
        $array_hoi_dong_thi_temp = str_replace("\"", "", $array_hoi_dong_thi_temp);

        $html = '<table border="1" style="width: 100%;border-collapse: collapse;" id="table_data" summary="Code page support in different versions of MS Windows."   ><thead>';
        $html .= '<tr >';
        $html .= '<th style="text-align: center">STT</th>';
        $html .= '<th style="text-align: center">Chứng chỉ</th>';
        $html .= '<th style="text-align: center">Khóa thi</th>';
        $html .= '<th style="text-align: center">Số bằng đã cấp</th>';
        $html .= '<th style="text-align: center">Ghi chú</th>';
        $html .= '</tr>';
        $html .= '</thead>';
        $html .= '<tbody>';
        $i = 0;
        foreach ($array_hoi_dong_thi as $array_hoi_dong_thi) {
         
            $ten_hoi_dong_thi = DB::table('hoi_dong_this')->where('id',$array_hoi_dong_thi)->pluck('ten_hoi_dong_thi');
            $html .= '<tr>';
            $html .= '<td style="text-align: center" colspan="5">' . $ten_hoi_dong_thi . '</td>';
            $html .= '</tr>';

            foreach ($array_chung_chi as $array_chung_chi ) {
                $ten_chung_chi = DB::table('chung_chis')->where('id',$array_chung_chi)->pluck('ten_chung_chi');
                

                $query_khoa_thi = 'select khoa_this.id, khoa_this.ma_khoa_thi FROM hoc_viens '
                . ' INNER JOIN khoa_this ON hoc_viens.KhoaThi_Id = khoa_this.id'
                . ' INNER JOIN hoi_dong_this ON khoa_this.HoiDongThi_Id = hoi_dong_this.id'
                . ' INNER JOIN chung_chis ON hoc_viens.ChungChi_Id = chung_chis.id'
                . ' where hoi_dong_this.id = \'' . $array_hoi_dong_thi. '\''
                . ' and chung_chis.id = \'' . $array_chung_chi . '\''
                . ' and khoa_this.id in ' . $array_khoa_thi_temp
                . ' and DATEDIFF(str_to_date(\'' . $tu_ngay . '\',"%d/%m/%Y"),str_to_date(khoa_this.ngay_thi,"%d/%m/%Y")) <= 0  '
                . ' and DATEDIFF(str_to_date(\'' . $den_ngay . '\',"%d/%m/%Y"),str_to_date(khoa_this.ngay_thi,"%d/%m/%Y")) >= 0 '
                . ' GROUP BY khoa_this.id';

                 
                $results_khoa_thi = DB::select($query_khoa_thi);

                foreach ($results_khoa_thi as $results_khoa_thi) {
                    $i++;
                        $results_pass = DB::table('hoc_viens')
                                            ->where('KhoaThi_Id',$results_khoa_thi->id)
                                            ->where('so_hieu_bang','!=','')
                                            ->count('so_hieu_bang');
                    $html .= '<tr>';
                    $html .= '<td style="text-align: center">' . $i . '</td>';
                    $html .= '<td style="text-align: center">' . $ten_chung_chi . '</td>';
                    $html .= '<td style="text-align: center">' . $results_khoa_thi->ma_khoa_thi . '</td>';
                    $html .= '<td style="text-align: center">' . $results_pass. '</td>';
                    $html .= '<td style="text-align: center"></td>';
                    $html .= '</tr>';
                }
            }

        }
 
        $query_count_dat = 'select count(*) as dat FROM hoc_viens '
                . ' INNER JOIN khoa_this ON hoc_viens.KhoaThi_Id = khoa_this.id'
                . ' INNER JOIN hoi_dong_this ON khoa_this.HoiDongThi_Id = hoi_dong_this.id'
                . ' INNER JOIN chung_chis ON hoc_viens.ChungChi_Id = chung_chis.id'
                . ' where hoi_dong_this.id in ' . $array_hoi_dong_thi_temp
                . ' and khoa_this.id in ' . $array_khoa_thi_temp
                . ' and chung_chis.id in ' . $array_chung_chi_temp
                . ' and DATEDIFF(str_to_date(\'' . $tu_ngay . '\',"%d/%m/%Y"),str_to_date(khoa_this.ngay_thi,"%d/%m/%Y")) <= 0  '
                . ' and DATEDIFF(str_to_date(\'' . $den_ngay . '\',"%d/%m/%Y"),str_to_date(khoa_this.ngay_thi,"%d/%m/%Y")) >= 0 '
                . ' and hoc_viens.so_hieu_bang <> \'\'';
                // echo $query_count_dat;
        $results_count_dat = DB::select($query_count_dat);
        foreach ($results_count_dat as $results_count_dat) {
            $results_count_dat = $results_count_dat->dat;
        }
        
        $html .= '<tr>';
        $html .= '<td colspan="3" style="text-align: center">Tổng số bằng</td>';
        $html .= '<td colspan="1" style="text-align: center">' . $results_count_dat . '</td>';
        $html .= '<td colspan="1" style="text-align: center"></td>';
        $html .= '</tr>';
        $html .= '</tbody>';
        $html .= '</table>';
        echo $html;
    }


}
